/**
 * 
 */

$(function(){
	
	//查询
	$("#btnSearch").click(function(){
		var formSerialize = $("#form").serializeObject();
		var v = JSON.stringify(formSerialize);
		$("#v").val(encodeURIComponent(v));
		form.submit();
	});
	
	
});

function toSet(id) {
	
	$.layer({
	    type: 2,
	    shade: [0],
	    fix: false,
	    title: '设置关键词',
	    maxmin: false,
	    iframe: {src : global.rootPath + "/adv/keyword/setKeyword?id="+id},
	    area: ['350px' , '330px'],
	    close: function(index){
	    }
	});
}

function set() {
	var id = $("#id").val();
	var keySort = $("#keySort").val();
	
	if (null == keySort || "" == keySort) {
		layer.tips("排序号不能为空", $("#keySort") , {guide: 3, time: 3,more:true});
		return false;
	} else {
		if (isNaN(keySort)) {
			layer.tips("排序号必须为有效数字", $("#keySort") , {guide: 3, time: 3,more:true});
			return false;	
		}
	}
	
	var len = $("input[name='display']:checked").length;
	var display = 0;
	if (len > 0) display = 1;
	
	security.ajax({
		url : global.rootPath + "/adv/keyword/saveKeyword",
		data : {
			keySort: keySort,
			id : id,
			display : display
			
		},
		beforeSend : function(){
			security.showLoading();
		},
		success : function(code,msg) {
			parent.location.reload();
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		},
		error : function(message) {
			parent.layer.msg(message, 3);
		}
	});
	
	
}


function cancel(id){
	
	$.layer({
	    shade: [0],
	    area: ['auto','auto'],
	    dialog: {
	        msg: '是否确定注销该商家信息？',
	        btns: 2,                    
	        type: 4,
	        btn: ['确定','取消'],
	        yes: function(){
	        	security.ajax({
	        		url : global.rootPath + "/adv/partner/cancel",
	        		data : {
	        			id : id
	        		},
	        		beforeSend : function(){
	        			security.showLoading();
	        		},
	        		success : function(code,msg) {
	        			if (msg == "") msg = "注销成功";
	        			security.showSuccess(msg,refresh);
	        		},
	        		error : function(message) {
	        			security.showError(message);
	        		}
	        	});
	        }, no: function(){
	        }
	    }
	});
	
}

function closeIframe() {
	var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

function refresh() {
	var formSerialize = $("#form").serializeObject();
	var v = JSON.stringify(formSerialize);
	$("#v").val(encodeURIComponent(v));
	form.submit();
}